﻿using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.ReadApi.Command.Raddit.BW;
using U.B.Repistory;

namespace U.B.ReadApi.CommandHander.Raddit.BWHA
{
    public class GetPicCommandHander : IRequestHandler<GetPicCommand, ApiResult<Picture>>
    {
        public readonly IRepistory<Picture> _Picrepistory;
        public GetPicCommandHander(IRepistory<Picture> picrepistory)
        {
            _Picrepistory = picrepistory;
        }
        public Task<ApiResult<Picture>> Handle(GetPicCommand request, CancellationToken cancellationToken)
        {
           ApiResult<Picture> apiResult = new ApiResult<Picture>();
            var result = _Picrepistory.GetAll().FirstOrDefault(x => x.BatchId == request.BatchId&&x.PicType==request.PicType);
            apiResult.code = Renum.显示成功;
            apiResult.Message = Renum.显示成功.ToString();
            apiResult.Data = result;
            return Task.FromResult(apiResult);
        }
    }
}
